div<template>
  <RouterView></RouterView>
  <div class="login-register">
    <div class="contain">
      <div class="big-box" :class="{ active: isLogin }">
        <!--  -->
        <div class="big-contain" key="bigContainLogin" v-if="isLogin">
          <div class="btitle">门诊医生登录</div>
          <div class="bform">
            <div class="d-input">
              <el-icon style="margin-right: 10px;" size="30px">
                <User />
              </el-icon>
              <span style="color: red;" v-if="form.loginname.length === 0">*</span>
              <span style="visibility:hidden" v-else>*</span>
              <input @input="docError=false" type="text" placeholder="请填写用户名" v-model="form.loginname">

            </div>
            <div class="d-psw">
              <el-icon style="margin-right: 10px;" size="30px">
                <Key />
              </el-icon>
              <span style="color: red;" v-if="form.userpwd.length === 0">*</span>
              <span style="visibility:hidden" v-else>*</span>
              <input @input="docError = false" type="password" placeholder="请填写密码" v-model="form.userpwd">
            </div>
            <span class="errTips" v-if="docError">* 用户名或密码填写错误 *</span>

          </div>
          <button class="bbutton" @click="register_login">登录</button>
        </div>
        <!-- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -->
        <div class="big-contain" key="bigContainRegister" v-else>
          <div class="btitle">管理员登录</div>
          <div class="bform">
            <div class="d-input">
              <el-icon style="margin-right: 10px;" size="25px">
                <User />
              </el-icon>
              <span style="color: red;" v-if="form.loginname.length === 0">*</span>
              <span style="visibility:hidden" v-else>*</span>
              <input type="text" placeholder="请填写用户名" v-model="form.loginname">
            </div>
            <div class="d-psw">
              <el-icon style="margin-right: 10px;" size="25px">
                <Key />
              </el-icon>
              <span style="color: red;" v-if="form.userpwd.length === 0">*</span>
              <span style="visibility:hidden" v-else>*</span>
              <input type="password" placeholder="请填写密码" v-model="form.userpwd">

            </div>

            <span class="errTips" v-if="admError">* 用户名或密码填写错误 *</span>

          </div>
          <div class="operation">
          <button class="one_buttons" @click="manager_login">登录</button>
          <button class="two_buttons" @click="add_manager">注册</button>
          </div>
        </div>
      </div>


      <div class="small-box" :class="{ active: isLogin }">
        <div class="small-contain-right" key="smallContainRegister" v-if="isLogin">
          <div class="stitle">你好，门诊医生</div>
          <p class="scontent">为病人看诊</p>
          <button class="sbutton" @click="changeType">切换到管理员</button>
        </div>
        <div class="small-contain-left" key="smallContainLogin" v-else>
          <div class="stitle">你好，管理员</div>
          <p class="scontent">开始系统管理</p>
          <button class="sbutton" @click="changeType">切换到门诊医生</button>
        </div>
      </div>

    </div>
  </div>
</template>
  
<script setup>

import { User, Key } from "@element-plus/icons-vue";
import $axios from "../utils/axios.js";
import { ref } from 'vue'
import { useRouter } from "vue-router";
const router = useRouter();
const isLogin = ref(true);
const docError = ref(false)
import { ElMessage } from 'element-plus'

const admError = ref(false)
const form = ref({
  loginname: 'zzj',

  userpwd: '1x'
})

const backgrounds = [
  '../imgs/reg.jpg',
  '../imgs/see.jpg'
];
const currentBackground = ref(0);


const changeType = () => {
  isLogin.value = !isLogin.value
  form.value.loginname = ''

  form.value.userpwd = ''


  currentBackground.value++;
  if (currentBackground.value === backgrounds.length) {
    currentBackground.value = 0;
  }


}
const register_login = async () => {
  if(form.value.loginname.length == 0||form.value.userpwd.length==0){
    console.log("hhhhhhh");
    
    ElMessage({
      showClose: true,
      message: '请填写用户名和密码',
      type: 'error',
    })
  }
  const send = {
    
    loginname: form.value.loginname,
    password: form.value.userpwd,
  }
  console.log(send);
  const path = "/register/q/login"
  const { data: res } = await $axios.post(
    path,
    send,
    {
      headers: {
        'Content-Type':
          'application/json; charset=UTF-8' //将表单数据传递转化为form-data类型
      }
    }
  )
  console.log("res", res);
  // await formE1.validate(async(valid) => {});
  ////将用户信息存入SessionStorage
  // let empObj=res.result;
  //     console.log("empObj",empObj);
  //     let jsonStr=JSON.stringify(empObj);
  //     sessionStorage.setItem("empJSON",jsonStr);//键-值对
  //     sessionStorage.setItem("empno",empObj.empno+"")//为了保证转化成字符串
  //     sessionStorage.setItem("token",empObj.token)//token肯定是字符串
  //     sessionStorage.setItem("roleId",empObj.empno+"")//角色
  //     // 使用编程式路由实现页面跳转
  console.log(docError.value);
  if(res.code==201){
    docError.value=true;
  }
  else if(res.code==200){
    console.log(res.msg); 
    let empObj = res.result;
    console.log("empObj", empObj);
    let jsonStr = JSON.stringify(empObj);
    sessionStorage.setItem("empJSON", jsonStr);//键-值对
    sessionStorage.setItem("regnum", empObj.regnum + "")//为了保证转化成字符串
    sessionStorage.setItem("loginname", empObj.loginname)//昵称
    sessionStorage.setItem("name", empObj.name + "")//真实姓名
    sessionStorage.setItem("password", empObj.password + "")//密码
    sessionStorage.setItem("createtime", empObj.createtime + "")//注册时间

    sessionStorage.setItem("token", empObj.token + "")//token
    router.push("/winRegist");//记得把这个放到后端检验之后
  }
  
}
////////////////////////////////


const manager_login = async () => {
  
  const send = {
    
    loginname: form.value.loginname,
    password: form.value.userpwd,
  }
  console.log(send);
  const path = "/manager/q/login"
  const { data: res } = await $axios.post(
    path,
    send,
    {
      headers: {
        'Content-Type':
          'application/json; charset=UTF-8' //将表单数据传递转化为form-data类型
      }
    }
  )
  if(res.code == 200) {

    router.push("/deptView");//记得把这个放到后端检验之后
  }
  else if(res.code == 201) {
  console.log("res", res);
  admError.value=true;
  console.log(admError);
  }
}



</script>
  
  
<style scoped="scoped" lang="scss">
$TransTime: 0.8s;
$TransTimeSmall: $TransTime;
$TransTimeBig: $TransTime+0.15s;

.login-register {
  width: 100vw;
  height: 100vh;
  box-sizing: border-box;
  background-image: url("../imgs/see.jpg");
  background-size: cover;
  background-repeat: no-repeat;
}

.contain {
  width: 60%;
  height: 60%;
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgb(255, 255, 255, 0.7);
  border-radius: 20px;
  box-shadow: 0 0 3px #f0f0f0,
    0 0 6px #f0f0f0;
}

.big-box {
  width: 70%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0%;//！！！之前为30%，可正常滑动白框部分
  transform: translateX(0%);
  transition: all $TransTimeBig;
}

.big-contain {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.btitle {
  font-size: 1.5em;
  font-weight: bold;
  color: rgb(57, 167, 176);
}

.bform {
  width: 100%;
  height: 40%;
  padding: 2em 0;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;

  .d-input {
    width: 71.8%;

    display: flex;
    align-items: center;
    margin-bottom: 10px;
    /* 调整每组之间的间距 */

  }

  .d-psw {
    width: 71.8%;
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    /* 调整每组之间的间距 */
  }
}

.bform .errTips {
  display: block;
  width: 50%;
  text-align: left;
  color: red;
  font-size: 0.7em;
  margin-left: 1em;
}

.bform input {
  width: 100%;
  height: 70px;
  border: none;
  outline: none;
  border-radius: 10px;
  padding-left: 2em;
  background-color: #f0f0f0;
  font-size: large;

}



.small-box {


  width: 30%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 100%;//！！！之前为0，可正常滑动蓝框
  transform: translateX(-100%);//！！！之前为0，可正常滑动蓝框
  transition: all $TransTimeSmall; //从右往左
  border-top-left-radius: inherit;
  border-bottom-left-radius: inherit;

  .small-contain-left {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, rgb(119, 173, 178), rgb(24, 74, 212), rgb(132, 154, 234));
    // background: linear-gradient(135deg, rgb(255, 0, 0), rgb(255, 128, 0), rgb(255, 255, 0));
  }

  .small-contain-right {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(-135deg, rgb(119, 173, 178), rgb(24, 74, 212), rgb(132, 154, 234));

  }
}



.stitle {
  font-size: 1.5em;
  font-weight: bold;
  color: #fff;
}

.scontent {
  font-size: 0.8em;
  color: #fff;
  text-align: center;
  padding: 2em 4em;
  line-height: 1.7em;
}

.sbutton {
  width: 65%;
  height: 40px;
  border-radius: 24px;
  border: 1px solid #fff;
  outline: none;
  // background-color: transparent;
  background: radial-gradient(rgb(24, 74, 212), #79bbff, );
  color: #ffffff;
  font-size: 0.9em;
  cursor: pointer;
}

.big-box.active {
  left: 0;
  
  transition: all $TransTimeBig;
}

.small-box.active {
  left: 100%;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-top-right-radius: inherit;
  border-bottom-right-radius: inherit;
  transform: translateX(-100%);
  transition: all $TransTimeSmall;
  //animation: curveAnimation 4s ;//infinite,加上后可以一直循环
}

@keyframes curveAnimation {
  0% {
    transform: translateX(0);
  }

  25% {
    transform: translate(200px, 200px);
    animation-timing-function: cubic-bezier(0.42, 0, 0.58, 1);
  }

  50% {
    transform: translate(400px, 0px);
    animation-timing-function: cubic-bezier(0.42, 0, 0.58, 1);
  }

  75% {
    transform: translateX(200px, -200px);
    animation-timing-function: cubic-bezier(0.42, 0, 0.58, 1);
  }

  100% {
    transform: translateX(0);
  }
}
.operation{
  align-items: center;
  flex-direction: column;
  justify-content: space-around;
   
  width: 80%;
  .one_buttons{
    width: 25%;
    height: 40px;
    margin-left: 20%;
    border-radius: 24px;
    border: none;
    outline: none;
    background-color: rgb(45, 162, 96);
    color: #fff;
    font-size: 0.9em;
  }
  .two_buttons{
    width: 25%;
    height: 40px;
    margin-left: 10%;
    border-radius: 24px;
    border: none;
    outline: none;
    background-color: rgb(45, 162, 96);
    color: #fff;
    font-size: 0.9em;
  }
}

.bbutton {
  width: 20%;
  height: 40px;
  border-radius: 24px;
  border: none;
  outline: none;
  // background: radial-gradient(rgb(24, 74, 212),rgba(255, 255, 255),);
  background-color: rgb(45, 162, 96);
  color: #fff;
  font-size: 0.9em;
  cursor: pointer;
}
</style>
  